home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / READER_1 / FDS__1_0 / TEXT_FD_ / TEXTFD.P < prev   
Text File  |  1992-07-19  |  18KB  |  793 lines

  1. unit TextFD;
  2.  
  3. interface
  4.  
  5.     uses
  6.         PrintTraps, Script, FormatDriver;
  7.  
  8.     function Main (message: Integer; window: WindowPtr; param1, param2: LongInt): LongInt;
  9.  
  10. implementation
  11.  
  12.     function DoOpen (window: WindowPtr; fileName: StringPtr; vRefNum: Integer): OSErr;
  13.     FORWARD;
  14.     procedure DoClose (window: WindowPtr);
  15.     FORWARD;
  16.     function DoPrint (window: WindowPtr; printHdl: THPrint): OSErr;
  17.     FORWARD;
  18.     procedure DoCopy (window: WindowPtr);
  19.     FORWARD;
  20.     procedure DoSelectAll (window: WindowPtr);
  21.     FORWARD;
  22.     procedure DoMenuSelect (window: WindowPtr; menuID, menuItem: Integer);
  23.     FORWARD;
  24.     procedure DoMenuUpdate (window: WindowPtr);
  25.     FORWARD;
  26.     procedure DoDraw (window: WindowPtr; updateRgn: RgnHandle);
  27.     FORWARD;
  28.     procedure DoResize (window: WindowPtr);
  29.     FORWARD;
  30.     procedure DoActivate (window: WindowPtr);
  31.     FORWARD;
  32.     procedure DoDeactivate (window: WindowPtr);
  33.     FORWARD;
  34.     function DoInContent (window: WindowPtr; mouseLoc: Point; modifiers: Integer): OSErr;
  35.     FORWARD;
  36.     function DoInControl (window: WindowPtr; mouseLoc: Point; control: ControlHandle): OSErr;
  37.     FORWARD;
  38.  
  39.     function Main (message: Integer; window: WindowPtr; param1, param2: LongInt): LongInt;
  40.     begin
  41.         Main := noErr;
  42.         case message of
  43.             rmOpen: 
  44.                 Main := DoOpen(window, StringPtr(param1), LoWord(param2));
  45.             rmClose: 
  46.                 DoClose(window);
  47.             rmPrint: 
  48.                 Main := DoPrint(window, THPrint(param1));
  49.             rmCopy: 
  50.                 DoCopy(window);
  51.             rmSelectAll: 
  52.                 DoSelectAll(window);
  53.             rmMenuSelect: 
  54.                 DoMenuSelect(window, param1, param2);
  55.             rmMenuUpdate: 
  56.                 DoMenuUpdate(window);
  57.             rmDraw: 
  58.                 DoDraw(window, RgnHandle(param1));
  59.             rmResize: 
  60.                 DoResize(window);
  61.             rmActivate: 
  62.                 DoActivate(window);
  63.             rmDeactivate: 
  64.                 DoDeactivate(window);
  65.             rmInContent: 
  66.                 Main := DoInContent(window, Point(param1), LoWord(param2));
  67.             rmInControl: 
  68.                 Main := DoInControl(window, Point(param1), ControlHandle(param2));
  69.         end;
  70.     end;
  71.  
  72.     const
  73.         kControlInvisible = 0;
  74.         kControlVisible = $FF;
  75.         kCRChar = 13;
  76.  
  77.     type
  78.         DocumentRecord = record
  79.                 textH: TEHandle;
  80.                 vControl: ControlHandle;
  81.                 searchLoc: Integer;
  82.                 searchStr: Str255;
  83.                 clikLoop: ProcPtr;
  84.             end;
  85.         DocumentPtr = ^DocumentRecord;
  86.         DocumentHdl = ^DocumentPtr;
  87.  
  88. { ========== support routines ========== }
  89.  
  90.     procedure BeginFDriver (window: WindowPtr; var document: DocumentHdl);
  91.     begin
  92.         document := DocumentHdl(GetWRefCon(window));
  93.         HLock(Handle(document));
  94.     end;
  95.  
  96.     procedure EndFDriver (document: DocumentHdl);
  97.     begin
  98.         HUnlock(Handle(document));
  99.     end;
  100.  
  101.     procedure GetViewRect (portRect: Rect; var viewRect: Rect);
  102.     begin
  103.         viewRect := portRect;
  104.         InsetRect(viewRect, 2, 2);
  105.         viewRect.right := viewRect.right - 16;
  106.     end;
  107.  
  108.     procedure AdjustViewRect (textH: TEHandle);
  109.     begin
  110.         with textH^^, textH^^.viewRect do
  111.             bottom := (((bottom - top) div lineHeight) * lineHeight) + top;
  112.     end;
  113.  
  114.     procedure AdjustTE (document: DocumentHdl);
  115.         var
  116.             value: Integer;
  117.     begin
  118.         with document^^, document^^.textH^^ do
  119.             TEScroll(0, (viewRect.top - destRect.top) - (GetCtlValue(vControl) * lineHeight), textH);
  120.     end;
  121.  
  122.     procedure AdjustVControl (document: DocumentHdl; canRedraw: Boolean);
  123.         var
  124.             value: Integer;
  125.             lines: Integer;
  126.             max: Integer;
  127.             oldValue: Integer;
  128.             oldMax: Integer;
  129.     begin
  130.         with document^^ do
  131.             begin
  132.                 oldValue := GetCtlValue(vControl);
  133.                 oldMax := GetCtlMax(vControl);
  134.                 lines := textH^^.nLines;
  135.                 if Ptr(ORD(textH^^.hText^) + textH^^.teLength - 1)^ = kCRChar then
  136.                     lines := lines + 1;
  137.                 max := lines - ((textH^^.viewRect.bottom - textH^^.viewRect.top) div textH^^.lineHeight);
  138.                 if max < 0 then
  139.                     max := 0;
  140.                 SetCtlMax(vControl, max);
  141.                 value := (textH^^.viewRect.top - textH^^.destRect.top) div textH^^.lineHeight;
  142.                 if value < 0 then
  143.                     value := 0
  144.                 else if value > max then
  145.                     value := max;
  146.                 SetCtlValue(vControl, value);
  147.                 if canRedraw and ((max <> oldMax) or (value <> oldValue)) then
  148.                     ShowControl(vControl);
  149.             end;
  150.     end;
  151.  
  152.     procedure AdjustScrollSizes (window: WindowPtr; document: DocumentHdl);
  153.         var
  154.             teRect: Rect;
  155.     begin
  156.         GetViewRect(window^.portRect, teRect);
  157.         with document^^, window^.portRect do
  158.             begin
  159.                 textH^^.viewRect := teRect;
  160.                 AdjustViewRect(textH);
  161.                 MoveControl(vControl, right - 15, -1);
  162.                 SizeControl(vControl, 16, (bottom - top) - (15 - 2));
  163.             end;
  164.     end;
  165.  
  166.     procedure AdjustScrollbars (window: WindowPtr; document: DocumentHdl; needsResize: Boolean);
  167.         var
  168.             oldMax: Integer;
  169.             oldValue: Integer;
  170.     begin
  171.         with document^^ do
  172.             begin
  173.                 vControl^^.contrlVis := kControlInvisible;
  174.                 if needsResize then
  175.                     AdjustScrollSizes(window, document);
  176.                 AdjustVControl(document, not needsResize);
  177.                 vControl^^.contrlVis := kControlVisible;
  178.             end;
  179.     end;
  180.  
  181. {$PUSH}
  182.  {$Z+}
  183.     procedure PascalClikLoop;
  184.         var
  185.             window: WindowPtr;
  186.             document: DocumentHdl;
  187.             region: RgnHandle;
  188.     begin
  189.         window := FrontWindow;
  190.         document := DocumentHdl(GetWRefCon(window));
  191.         region := NewRgn;
  192.         GetClip(region);
  193.         ClipRect(window^.portRect);
  194.         AdjustVControl(document, true);
  195.         SetClip(region);
  196.         DisposeRgn(region);
  197.     end;
  198. {$POP}
  199.  
  200. {$PUSH}
  201.  {$Z+}
  202.     function GetOldClikLoop: ProcPtr;
  203.         var
  204.             document: DocumentHdl;
  205.     begin
  206.         GetOldClikLoop := DocumentHdl(GetWRefCon(FrontWindow))^^.clikLoop;
  207.     end;
  208. {$POP}
  209.  
  210.     procedure MyClikLoop;
  211.     EXTERNAL;
  212.  
  213.     procedure ActionProc (control: ControlHandle; part: Integer);
  214.         var
  215.             window: WindowPtr;
  216.             document: DocumentHdl;
  217.             amount: Integer;
  218.             value: Integer;
  219.             max: Integer;
  220.     begin
  221.         if part <> 0 then
  222.             begin
  223.                 window := control^^.contrlOwner;
  224.                 document := DocumentHdl(GetWRefCon(window));
  225.                 with document^^, document^^.textH^^ do
  226.                     begin
  227.                         case part of
  228.                             inUpButton: 
  229.                                 amount := 1;
  230.                             inDownButton: 
  231.                                 amount := -1;
  232.                             inPageUp: 
  233.                                 amount := (viewRect.bottom - viewRect.top) div lineHeight;
  234.                             inPageDown: 
  235.                                 amount := -((viewRect.bottom - viewRect.top) div lineHeight);
  236.                         end;
  237.                         value := GetCtlValue(control);
  238.                         max := GetCtlMax(control);
  239.                         amount := value - amount;
  240.                         if amount < 0 then
  241.                             amount := 0
  242.                         else if amount > max then
  243.                             amount := max;
  244.                         SetCtlValue(control, amount);
  245.                         amount := value - amount;
  246.                         if amount <> 0 then
  247.                             TEScroll(0, amount * lineHeight, textH);
  248.                     end;
  249.             end;
  250.     end;
  251.  
  252.     procedure GetAString (dialog: DialogPtr; item: integer; var str: Str255);
  253.         var
  254.             itemType: Integer;
  255.             itemBox: Rect;
  256.             itemHdl: Handle;
  257.     begin
  258.         GetDItem(dialog, item, itemType, itemHdl, itemBox);
  259.         GetIText(itemHdl, str);
  260.     end;
  261.  
  262.     procedure DoFind (document: DocumentHdl; searchStr: Str255);
  263.         var
  264.             itemHit: Integer;
  265.             done: Boolean;
  266.             newLocation: LongInt;
  267.             theText: Handle;
  268.             keySize: LongInt;
  269.             keyPtr: Ptr;
  270.     begin
  271.         theText := document^^.textH^^.hText;
  272.         HLock(theText);
  273.  
  274.         keySize := length(searchStr);
  275.         keyPtr := pointer(ORD(@searchStr) + 1);
  276.         done := FALSE;
  277.         newLocation := -keySize;
  278.  
  279.         repeat
  280.             newLocation := Munger(theText, newLocation + keySize, keyPtr, keySize, nil, 0);
  281.             if newLocation < 0 then
  282.                 done := TRUE
  283.             else if CharByte(theText^, newLocation) <= 0 then
  284.                 done := TRUE;
  285.         until done;
  286.  
  287.         if newLocation >= 0 then
  288.             begin
  289.                 TESetSelect(newLocation, newLocation + keySize, document^^.textH);
  290.                 document^^.searchLoc := newLocation + keySize;
  291.                 document^^.searchStr := searchStr;
  292.                 AdjustVControl(document, true);
  293.             end
  294.         else
  295.             begin
  296.                 searchStr := concat('╥', searchStr, '╙ not found.');
  297.                 ParamText(searchStr, '', '', '');
  298.                 Sysbeep(1);
  299.                 itemHit := NoteAlert(ALRTinfo, nil);
  300.                 document^^.searchLoc := -1;
  301.                 document^^.searchStr := '';
  302.             end;
  303.         HUnlock(theText);
  304.     end;
  305.  
  306.     procedure DoFindNext (document: DocumentHdl);
  307.         var
  308.             itemHit: Integer;
  309.             done: Boolean;
  310.             newLocation: LongInt;
  311.             theText: Handle;
  312.             keySize: LongInt;
  313.             keyPtr: Ptr;
  314.             theStr: Str255;
  315.     begin
  316.         with document^^ do
  317.             begin
  318.                 theText := textH^^.hText;
  319.                 HLock(theText);
  320.  
  321.                 theStr := searchStr;
  322.                 keySize := length(theStr);
  323.                 keyPtr := pointer(ORD(@theStr) + 1);
  324.                 done := FALSE;
  325.                 newLocation := searchLoc;
  326.             end;
  327.  
  328.         repeat
  329.             newLocation := Munger(theText, newLocation + keySize, keyPtr, keySize, nil, 0);
  330.             if newLocation < 0 then
  331.                 done := TRUE
  332.             else if CharByte(theText^, newLocation) <= 0 then
  333.                 done := TRUE;
  334.         until done;
  335.  
  336.         if newLocation >= 0 then
  337.             begin
  338.                 TESetSelect(newLocation, newLocation + keySize, document^^.textH);
  339.                 document^^.searchLoc := newLocation + keySize;
  340.                 AdjustVControl(document, true);
  341.             end
  342.         else
  343.             begin
  344.                 theStr := concat('╥', theStr, '╙ not found.');
  345.                 ParamText(theStr, '', '', '');
  346.                 Sysbeep(1);
  347.                 itemHit := NoteAlert(ALRTinfo, nil);
  348.                 document^^.searchLoc := -1;
  349.                 document^^.searchStr := '';
  350.             end;
  351.         HUnlock(theText);
  352.     end;
  353.  
  354. { ========== message handlers ========== }
  355.  
  356.     function DoOpen (window: WindowPtr; fileName: StringPtr; vRefNum: Integer): OSErr;
  357.         var
  358.             document: DocumentHdl;
  359.             error: OSErr;
  360.             refNum: Integer;
  361.             logEOF: LongInt;
  362.             theHdl: Handle;
  363.             theText: TEHandle;
  364.             destRect: Rect;
  365.             viewRect: Rect;
  366.     begin
  367.         error := FSOpen(fileName^, vRefNum, refNum);
  368.         if error <> noErr then
  369.             begin
  370.                 DoOpen := error;
  371.                 Exit(DoOpen);
  372.             end;
  373.  
  374.         error := GetEOF(refNum, logEOF);
  375.         if error <> noErr then
  376.             begin
  377.                 DoOpen := error;
  378.                 error := FSClose(refNum);
  379.                 Exit(DoOpen);
  380.             end;
  381.         if logEOF > 32000 then
  382.             begin
  383.                 logEOF := 32000;
  384.                 InfoAlert(1000);
  385.             end;
  386.  
  387.         theHdl := NewHandle(logEOF);
  388.         if (theHdl = nil) then
  389.             begin
  390.                 DoOpen := memFullErr;
  391.                 error := FSClose(refNum);
  392.                 Exit(DoOpen);
  393.             end;
  394.  
  395.         HLock(theHdl);
  396.         error := FSRead(refNum, logEOF, theHdl^);
  397.         HUnlock(theHdl);
  398.         if error <> noErr then
  399.             begin
  400.                 DoOpen := error;
  401.                 DisposHandle(theHdl);
  402.                 error := FSClose(refNum);
  403.                 Exit(DoOpen);
  404.             end;
  405.  
  406.         error := FSClose(refNum);
  407.  
  408.         document := DocumentHdl(NewHandle(sizeof(DocumentRecord)));
  409.         if (document = nil) then
  410.             begin
  411.                 DoOpen := memFullErr;
  412.                 DisposHandle(theHdl);
  413.                 Exit(DoOpen);
  414.             end;
  415.  
  416.         TextFont(GetAppFont);
  417.         TextSize(GetDefFontSize);
  418.         SizeWindow(window, 500, window^.portRect.bottom - GetMBarHeight, false);
  419.         GetViewRect(window^.portRect, viewRect);
  420.         destRect := viewRect;
  421.         theText := TENew(destRect, viewRect);
  422.         if (MemError <> noErr) then
  423.             begin
  424.                 DoOpen := MemError;
  425.                 DisposHandle(Handle(document));
  426.                 DisposHandle(theHdl);
  427.                 Exit(DoOpen);
  428.             end;
  429.  
  430.         HLock(theHdl);
  431.         TESetText(theHdl^, GetHandleSize(theHdl), theText);
  432.         HUnlock(theHdl);
  433.         DisposHandle(theHdl);
  434.  
  435.         HLock(Handle(document));
  436.         with document^^ do
  437.             begin
  438.                 textH := theText;
  439.                 AdjustViewRect(textH);
  440.                 TEAutoView(TRUE, textH);
  441.                 clikLoop := textH^^.clikLoop;
  442.                 textH^^.clikLoop := @MyClikLoop;
  443.  
  444.                 vControl := GetNewControl(1000, window);
  445.                 AdjustVControl(document, false);
  446.  
  447.                 searchLoc := -1;
  448.                 searchStr := '';
  449.             end;
  450.         HUnlock(Handle(document));
  451.         SetWRefCon(window, LongInt(document));
  452.         DoOpen := noErr;
  453.     end;
  454.  
  455.     procedure DoClose (window: WindowPtr);
  456.         var
  457.             document: DocumentHdl;
  458.     begin
  459.         BeginFDriver(window, document);
  460.         with document^^ do
  461.             begin
  462.                 TEDispose(textH);
  463.             end;
  464.         EndFDriver(document);
  465.  
  466.         DisposHandle(Handle(document));
  467.     end;
  468.  
  469.     function PrintProc (printHdl: THPrint; textHdl: TEHandle): LongInt;
  470.         const
  471.             kBottomMargin = 22;
  472.             kLeftMargin = 15;
  473.             kRightMargin = 15;
  474.         var
  475.             thePrPort: TPPrPort;
  476.             firstPage: Integer;
  477.             lastPage: Integer;
  478.             numberOfCopies: Integer;
  479.             copies: Integer;
  480.             pageRect: Rect;
  481.             pageNumber: Integer;
  482.             rPage: Rect;
  483.             realNumberOfPages: Integer;
  484.             pageLen: Integer;
  485.             start: Integer;
  486.             finish: Integer;
  487.             counter: Integer;
  488.             tempRect: Rect;
  489.             tempRect2: Rect;
  490.             Lengths: array[1..999] of Integer;
  491.             theText: Handle;
  492.             thePtr: Ptr;
  493.     begin
  494.         numberOfCopies := printHdl^^.prJob.iCopies;
  495.         firstPage := printHdl^^.prJob.iFstPage;
  496.         lastPage := printHdl^^.prJob.iLstPage;
  497.         printHdl^^.prJob.iFstPage := 1;
  498.         printHdl^^.prJob.iLstPage := 999;
  499.  
  500.         rPage := printHdl^^.prInfo.rPage;
  501.         pageRect := rPage;
  502.         with pageRect, textHdl^^ do
  503.             begin
  504.                 left := left + kLeftMargin;
  505.                 right := right - kRightMargin;
  506.                 bottom := bottom - kBottomMargin - (bottom - kBottomMargin) mod lineHeight;
  507.                 tempRect := destRect;
  508.                 destRect := pageRect;
  509.             end;
  510.         TECalText(textHdl);
  511.  
  512.         with pageRect, textHdl^^ do
  513.             begin
  514.                 tempRect2 := viewRect;
  515.                 pageLen := (rPage.bottom - rPage.top - kBottomMargin) div lineHeight;
  516.                 finish := nlines;
  517.                 start := 0;
  518.                 counter := 1;
  519.                 while start < finish do
  520.                     begin
  521.                         if (finish - start > pageLen) then
  522.                             Lengths[counter] := lineStarts[start + pageLen] - lineStarts[start]
  523.                         else
  524.                             Lengths[counter] := teLength - lineStarts[start];
  525.                         start := start + pageLen;
  526.                         counter := counter + 1;
  527.                     end;
  528.                 realNumberOfPages := counter - 1;
  529.                 destRect := tempRect;
  530.             end;
  531.         TECalText(textHdl);
  532.  
  533.         if (realNumberOfPages < lastPage) then
  534.             lastPage := realNumberOfPages;
  535.  
  536.         HLock(Handle(textHdl));
  537.         theText := textHdl^^.hText;
  538.         MoveHHi(theText);
  539.         HLock(theText);
  540.  
  541.         for copies := 1 to numberOfCopies do
  542.             begin
  543.                 thePrPort := PrOpenDoc(printHdl, nil, nil);
  544.                 if (PrError = noErr) then
  545.                     begin
  546.                         TextFont(textHdl^^.txFont);
  547.                         TextSize(textHdl^^.txSize);
  548.                         TextFace([]);
  549.                         pageNumber := firstPage;
  550.                         thePtr := theText^;
  551.                         for counter := 1 to (firstPage - 1) do
  552.                             thePtr := Pointer(ORD4(thePtr) + Lengths[counter]);
  553.                         while ((pageNumber <= lastPage) and (PrError = noErr)) do
  554.                             begin
  555.                                 PrOpenPage(thePrPort, nil);
  556.                                 if (PrError = noErr) then
  557.                                     TextBox(thePtr, Lengths[pageNumber], pageRect, teJustLeft);
  558.                                 PrClosePage(thePrPort);
  559.                                 if (PrError = noErr) then
  560.                                     thePtr := Pointer(ORD4(thePtr) + Lengths[pageNumber]);
  561.                                 pageNumber := pageNumber + 1;
  562.                             end;
  563.                     end;
  564.                 PrCloseDoc(thePrPort);
  565.             end;
  566.  
  567.         HUnlock(theText);
  568.         HUnlock(Handle(textHdl));
  569.  
  570.         PrintProc := PrError;
  571.     end;
  572.  
  573.     function DoPrint (window: WindowPtr; printHdl: THPrint): OSErr;
  574.         var
  575.             document: DocumentHdl;
  576.     begin
  577.         DoPrint := noErr;
  578.  
  579.         BeginFDriver(window, document);
  580.  
  581.         with document^^ do
  582.             DoPrint := PrintProc(printHdl, textH);
  583.  
  584.         EndFDriver(document);
  585.     end;
  586.  
  587.     procedure DoCopy (window: WindowPtr);
  588.         var
  589.             document: DocumentHdl;
  590.             error: OSErr;
  591.     begin
  592.         if (ZeroScrap <> noErr) then
  593.             Exit(DoCopy);
  594.  
  595.         BeginFDriver(window, document);
  596.  
  597.         with document^^ do
  598.             TECopy(textH);
  599.         error := TEToScrap;
  600.  
  601.         EndFDriver(document);
  602.     end;
  603.  
  604.     procedure DoSelectAll (window: WindowPtr);
  605.         var
  606.             document: DocumentHdl;
  607.     begin
  608.         BeginFDriver(window, document);
  609.  
  610.         with document^^ do
  611.             TESetSelect(0, 32767, textH);
  612.         AdjustScrollBars(window, document, false);
  613.         AdjustTE(document);
  614.  
  615.         EndFDriver(document);
  616.     end;
  617.  
  618.     procedure DoMenuSelect (window: WindowPtr; menuID, menuItem: Integer);
  619.         var
  620.             document: DocumentHdl;
  621.             dialog: DialogPtr;
  622.             itemHit: Integer;
  623.             theStr: Str255;
  624.             tempPort: GrafPtr;
  625.             itemType: Integer;
  626.             itemHdl: Handle;
  627.             itemRect: Rect;
  628.             menu: MenuHandle;
  629.     begin
  630.         if (menuID <> 1000) then
  631.             Exit(DoMenuSelect);
  632.  
  633.         BeginFDriver(window, document);
  634.  
  635.         case menuItem of
  636.             1: 
  637.                 begin
  638.                     GetPort(tempPort);
  639.                     dialog := GetNewDialog(1000, nil, pointer(-1));
  640.                     SetPort(dialog);
  641.                     GetDItem(dialog, 1, itemType, itemHdl, itemRect);
  642.                     InsetRect(itemRect, -4, -4);
  643.                     PenSize(3, 3);
  644.                     FrameRoundRect(itemRect, 16, 16);
  645.                     repeat
  646.                         ModalDialog(nil, itemHit);
  647.                     until (itemHit = 1) or (itemHit = 2);
  648.                     SetPort(tempPort);
  649.                     GetAString(dialog, 4, theStr);
  650.                     DisposDialog(dialog);
  651.                     if (itemHit = 1) and (theStr <> '') then
  652.                         DoFind(document, theStr)
  653.                     else
  654.                         document^^.searchLoc := -1;
  655.                 end;
  656.             2: 
  657.                 begin
  658.                     DoFindNext(document);
  659.                 end;
  660.         end;
  661.  
  662.         EndFDriver(document);
  663.     end;
  664.  
  665.     procedure DoMenuUpdate (window: WindowPtr);
  666.         var
  667.             document: DocumentHdl;
  668.             menu: MenuHandle;
  669.     begin
  670.         menu := GetMHandle(1000);
  671.         if menu = nil then
  672.             Exit(DoMenuUpdate);
  673.  
  674.         BeginFDriver(window, document);
  675.  
  676.         if (document^^.searchLoc = -1) then
  677.             DisableItem(menu, 2)
  678.         else
  679.             EnableItem(menu, 2);
  680.  
  681.         EndFDriver(document);
  682.     end;
  683.  
  684.     procedure DoDraw (window: WindowPtr; updateRgn: RgnHandle);
  685.         var
  686.             document: DocumentHdl;
  687.             theRect: Rect;
  688.     begin
  689.         BeginFDriver(window, document);
  690.  
  691.         theRect := updateRgn^^.rgnBBox;
  692.         TEUpdate(theRect, document^^.textH);
  693.  
  694.         EndFDriver(document);
  695.     end;
  696.  
  697.     procedure DoResize (window: WindowPtr);
  698.         var
  699.             document: DocumentHdl;
  700.     begin
  701.         BeginFDriver(window, document);
  702.  
  703.         AdjustScrollbars(window, document, true);
  704.         AdjustTE(document);
  705.  
  706.         EndFDriver(document);
  707.     end;
  708.  
  709.     procedure DoActivate (window: WindowPtr);
  710.         var
  711.             document: DocumentHdl;
  712.     begin
  713.         BeginFDriver(window, document);
  714.  
  715.         ClipRect(window^.portRect);
  716.         with document^^ do
  717.             begin
  718.                 ShowControl(vControl);
  719.                 TEActivate(textH);
  720.             end;
  721.  
  722.         EndFDriver(document);
  723.     end;
  724.  
  725.     procedure DoDeactivate (window: WindowPtr);
  726.         var
  727.             document: DocumentHdl;
  728.     begin
  729.         BeginFDriver(window, document);
  730.  
  731.         ClipRect(window^.portRect);
  732.         with document^^ do
  733.             begin
  734.                 TEDeactivate(textH);
  735.                 HideControl(vControl);
  736.             end;
  737. {with window^.portRect do}
  738. {begin}
  739. {MoveTo(right - 15, top);}
  740. {LineTo(right - 15, bottom - 15);}
  741. {end;}
  742.  
  743.         EndFDriver(document);
  744.     end;
  745.  
  746.     function DoInContent (window: WindowPtr; mouseLoc: Point; modifiers: Integer): OSErr;
  747.         var
  748.             document: DocumentHdl;
  749.     begin
  750.         DoInContent := noErr;
  751.  
  752.         BeginFDriver(window, document);
  753.  
  754.         with document^^ do
  755.             begin
  756.                 textH^^.clikLoop := @MyClikLoop;
  757.                 TEClick(mouseLoc, (BitAnd(modifiers, shiftKey) = shiftKey), textH);
  758.             end;
  759.  
  760.         EndFDriver(document);
  761.     end;
  762.  
  763.     function DoInControl (window: WindowPtr; mouseLoc: Point; control: ControlHandle): OSErr;
  764.         var
  765.             document: DocumentHdl;
  766.             part: Integer;
  767.             value: Integer;
  768.     begin
  769.         DoInControl := noErr;
  770.  
  771.         BeginFDriver(window, document);
  772.  
  773.         part := TestControl(control, mouseLoc);
  774.         if part = inThumb then
  775.             begin
  776.                 value := GetCtlValue(control);
  777.                 part := TrackControl(control, mouseLoc, nil);
  778.                 if part <> 0 then
  779.                     begin
  780.                         value := value - GetCtlValue(control);
  781.                         if value <> 0 then
  782.                             TEScroll(0, value * document^^.textH^^.lineHeight, document^^.textH);
  783.                     end;
  784.             end
  785.         else
  786.             begin
  787.                 value := TrackControl(control, mouseLoc, @actionProc);
  788.             end;
  789.  
  790.         EndFDriver(document);
  791.     end;
  792.  
  793. end.